package com.chenshanji.lease.common.service;

import org.springframework.stereotype.Service;

import java.util.Random;

@Service
public class AvatarService {
    private static final Random RANDOM = new Random();

    private static final String[] TOP_TYPES = { "NoHair", "Eyepatch", "Hat", "Hijab", "Turban" };
    private static final String[] ACCESSORIES_TYPES = { "Blank", "Kurt", "Prescription01", "Prescription02", "Round" };
    private static final String[] HAIR_COLORS = { "Auburn", "Black", "Blonde", "BlondeGolden", "Brown" };
    private static final String[] FACIAL_HAIR_TYPES = { "Blank", "BeardMedium", "BeardLight", "BeardMagestic" };
    private static final String[] CLOTHE_TYPES = { "BlazerShirt", "BlazerSweater", "CollarSweater", "GraphicShirt" };
    private static final String[] EYE_TYPES = { "Close", "Cry", "Default", "Dizzy", "EyeRoll" };
    private static final String[] MOUTH_TYPES = { "Concerned", "Default", "Disbelief", "Eating", "Grimace" };
    private static final String[] SKIN_COLORS = { "Tanned", "Yellow", "Pale", "Light", "Brown", "DarkBrown", "Black" };

    private static String getRandomElement(String[] array) {
        return array[RANDOM.nextInt(array.length)];
    }

    public String generateRandomAvatarUrl() {
        return "https://avataaars.io/?" +
                "avatarStyle=Circle" +
                "&topType=" + getRandomElement(TOP_TYPES) +
                "&accessoriesType=" + getRandomElement(ACCESSORIES_TYPES) +
                "&hairColor=" + getRandomElement(HAIR_COLORS) +
                "&facialHairType=" + getRandomElement(FACIAL_HAIR_TYPES) +
                "&clotheType=" + getRandomElement(CLOTHE_TYPES) +
                "&eyeType=" + getRandomElement(EYE_TYPES) +
                "&mouthType=" + getRandomElement(MOUTH_TYPES) +
                "&skinColor=" + getRandomElement(SKIN_COLORS);
    }
}
